package myJs.user

import myJs.Implicits._
import myJs.components.ExportDatComponent
import myJs.myPkg.bootstrap.Bootstrap.default._
import myJs.myPkg.jquery._
import myJs.tool.Tool
import org.scalajs.dom._
import org.scalajs.dom.ext.Ajax

import scala.concurrent.ExecutionContext.Implicits.global
import scala.scalajs.js
import scala.scalajs.js.Dynamic.{global => g}
import scala.scalajs.js.JSConverters._
import scala.scalajs.js.JSON
import scala.scalajs.js.annotation.{JSExport, JSExportTopLevel}

/**
 * Created by yz on 2019/4/25
 */
@JSExportTopLevel("ExportAllDatModal")
object ExportAllDatModal {

  val modalId="exportAllDatModal"
  val formId="form"

  @JSExport("init")
  def init = {
    bootStrapValidator
    val state=ExportDatComponent.State.init.copy(formJq = $(s"#${modalId} #${formId}"))
    val component = ExportDatComponent.component(state)().renderIntoDOM(document.querySelector(s"#${modalId} #myDat"))
    registerEvent
  }

  def registerEvent={

  }

  def bootStrapValidator = {
    val maxNumber = Double.MaxValue
    val dict = js.Dictionary(
      "feedbackIcons" -> js.Dictionary(
        "valid" -> "glyphicon glyphicon-ok",
        "invalid" -> "glyphicon glyphicon-remove",
        "validating" -> "glyphicon glyphicon-refresh",
      ),
      "fields" -> js.Dictionary(
        "sampleNum" -> {
          val info = "单文件样本数"
          js.Dictionary(
            "notEmpty" -> js.Dictionary(
              "message" -> s"${info}不能为空!"
            ),
            "validators" -> js.Dictionary(
              "integer" -> js.Dictionary(
                "message" -> s"${info}必须为整数",
              ),
              "between" -> js.Dictionary(
                "min" -> 1,
                "max" -> maxNumber,
                "message" -> s"${info}必须大于0",
              ),
            )
          )
        },
      )
    )
    g.$(s"#${modalId} #${formId}").bootstrapValidator(dict)
  }





}
